//
//  ViewController.m
//  UIScrollView的快速使用
//
//  Created by YQ05 on 2018/7/17.
//  Copyright © 2018年 YQ05. All rights reserved.
//

#import "ViewController.h"
#import "MKConstant.h"

#import "network.h"
#import "DB/DataPersist.h"

#import "Common/network/imgDownload/ViewController2TVC.h"
#import "menuViewController.h"
#import "aboutUs/aboutUsVC.h"
#import "Menu/MenutbVC.h"

#import "aboutUs/UIScrollView的快速使用-Bridging-Header.h"
#import "UIScrollView的快速使用-Swift.h"

#import "UIImageView+Cache.h"
#import "WKWebViewController.h"

//#import "Common/network/imgDownload/CustomCell.h"
#import "IndexCell.h"

#import "ItemViewController.h"
#import "Notification/NotificationVC.h"

#import "promotion/promotionTVC.h"
#import "testVC.h"

#import "contactTVC2.h"

#define SECTION_HEADER_HEIGHT 50

@interface ViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>{
    UIScrollView *scrollview;
   
    
    menuViewController *vc_menuVC; //滑动menu
    
    //aboutUsVC *vc_aboutUsOC;
    WKWebViewController *vc_WKWeb;
    MenutbVC *vc_CitySelect;
    
    NotificationVC *vc_Notification;
    
    UIView *loginView2;
    BOOL login2hidden;
    
    UITableView *tableView;  //下半部分 tableView
    NSMutableArray *indexArray;
    NSMutableArray *menuarr;
    NSMutableArray *homebannerarr;
    
    UIScrollView *sv_image;
    UIPageControl *pageControl;
    NSTimer *timer;
    int imageIndex;
    
    ItemViewController *itemVc;
    
    UIView* imgVC;
    
    promotionTVC *promotVC;
    testVC *testvc;
    
    contactTVC2 *contvc2;
}
//@property (nonatomic, strong) UITableView *tbView;
@property (nonatomic, strong) UIButton *registerBtn;
@property (nonatomic, strong) UIButton *aboutusOCBtn;
@property (nonatomic, strong) UIButton *aboutusSwiftBtn;


@property (nonatomic, strong) NSMutableArray *datasource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(setIndexView) name:@"getIndexNOTIF" object:nil];
    
    [self getnetworkData]; //获取网络信息
    [self loadingView];  //等待网络结果动画
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    //[self settableView];
    
}


- (void)settableView {
    //下半部分 tableView
    tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, UISCREEN_WIDTH, UISCREEN_HEIGHT-64)];
    [tableView  setSeparatorStyle:UITableViewCellSeparatorStyleNone]; //tableview提供的方法去除所有的分割线
    [self.view addSubview:tableView];
    
    tableView.bounces = NO;  //ios-tableView禁止上下弹性或一个方向弹性
    //tableView.allowsSelection = NO;  //取消选择
    tableView.dataSource = self;
    tableView.delegate = self;
    
    /**
     组合功能
     */
    //[self scrollview5];
    //[self addTopView];
    
    [self linshiBTNView ]; // 临时 test 按钮
    [self bookingview];
    /**
     组合功能
     */
    
    
    indexArray = [[NSMutableArray alloc]init];
    for (NSArray *array in menuarr) {
        NSDictionary *dic = [array firstObject];
        NSString *cate = [dic valueForKey:@"cate"];
        [indexArray addObject:cate];
    }
    

    self.automaticallyAdjustsScrollViewInsets = false;
    UIView *view_head = [[UIView alloc]initWithFrame:CGRectMake(0, 64, UISCREEN_WIDTH, 150)];
    view_head.backgroundColor = [UIColor whiteColor];
    //[self.view addSubview:view_head];
    tableView.tableHeaderView = view_head;
    
    sv_image = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, 150)];
    sv_image.contentSize = CGSizeMake(UISCREEN_WIDTH* homebannerarr.count , 0);
    sv_image.pagingEnabled = true;
    sv_image.directionalLockEnabled = true;
    sv_image.delegate = self;
    sv_image.showsHorizontalScrollIndicator = false;
    [view_head addSubview:sv_image];
    
    
    //NSLog(@"homebannerarr.count %lu",(unsigned long)homebannerarr.count);
    for (int index = 0; index < homebannerarr.count; index++) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(index * UISCREEN_WIDTH, 0, UISCREEN_WIDTH, 150)];

        [imageView mk_setImageWithUrl:self->homebannerarr[index] placeHolder:[UIImage imageNamed:@"loadinggray.png"] complete:^(UIImage *image, BOOL cache) {
       //img [UIImage imageNamed:@"default"] [UIImage animatedImageWithImages:images duration:duration]
//            NSLog(@"img url %@",self->homebannerarr[index]);
//            NSLog(@"img desc %@",[image description]);
        }];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.clipsToBounds = YES; //view添加view，并剪边(UIView属性clipsTobounds的应用)

//                UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(index*UISCREEN_WIDTH, 0, UISCREEN_WIDTH, 150)];
//                NSString *imagePath = testimgarr[index];//[NSString stringWithFormat:@"%d.png",index+1];
//                imageView.image = [UIImage imageNamed:imagePath];
//                imageView.contentMode = UIViewContentModeScaleToFill;
      [sv_image addSubview:imageView];
    }
    pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, 130, UISCREEN_WIDTH, 20)];
    pageControl.numberOfPages = homebannerarr.count;
    pageControl.currentPage = 0;
    pageControl.backgroundColor = [UIColor clearColor];
    pageControl.pageIndicatorTintColor = [UIColor grayColor];
    [view_head addSubview:pageControl];
    
    imageIndex = 0;
    timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(imagePlay) userInfo:nil repeats:true];
    
    //下半部分 tableView
    
    
    // 1 菜单栏按钮  方法1 ios11 设置菜单栏 右键 图片大小
    UIButton *menuBtn = [[UIButton alloc]initWithFrame:CGRectMake((UISCREEN_WIDTH - 40), 5, 30, 30)];
    
    [menuBtn.widthAnchor constraintEqualToConstant:30].active = YES;
    [menuBtn.heightAnchor constraintEqualToConstant:30].active = YES;
    //UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [menuBtn setImage:[UIImage imageNamed:@"menu.png"] forState:UIControlStateNormal];
    
    [menuBtn addTarget:self action:@selector(menuBtnAction) forControlEvents:UIControlEventTouchUpInside];

    //menuBtn.frame = CGRectMake(0, 5, 20, 20);
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:menuBtn];
    self.navigationItem.rightBarButtonItem  = backItem;
    

    
    //方法2:
    //self.newMenuViewController.navigationItem.leftBarButtonItem = backItem;
    //[self.navigationController.navigationBar addSubview:menuBtn];
//    UIImage *menuimg = [UIImage imageNamed:@"menu.png"];
//    UIBarButtonItem *rightMenuBtn = [[UIBarButtonItem alloc]initWithImage:menuimg style:UIBarButtonItemStylePlain target:self action:@selector(menuBtnAction)];
    //self.navigationItem.rightBarButtonItem = menuBtn;
    
    //    UIImage *image = [UIImage imageNamed:@"2.png"];
    //    UIImage *newImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //    UIBarButtonItem *bbi_login = [[UIBarButtonItem alloc]initWithImage:newImage style:UIBarButtonItemStyleDone target:self action:@selector(loginAction)];
    //    self.navigationItem.rightBarButtonItem = bbi_login;
    //    NSArray *bt_array = [[NSArray alloc]initWithObjects:bbi_login, nil];
    //    self.navigationItem.leftBarButtonItems = bt_array;
    
    // 2 2.1 坐标 2.2 navigationItem
    //[self.navigationItem setTitle:@"登陆"];
    UIButton *bt_qrcode = [[UIButton alloc]initWithFrame:CGRectMake((UISCREEN_WIDTH - 200) /2, 0, 200, 44)];
    [bt_qrcode setImage:[UIImage imageNamed:@"young_logo_280x70.png"] forState:UIControlStateNormal];
    [bt_qrcode addTarget:self action:@selector(qrcodeAction) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationController.navigationBar addSubview:bt_qrcode];
}

//#pragma mark tableView的取消选中状态的两个方法  里面什么也不用写
//-(void)setSelected:(BOOL)selected animated:(BOOL)animated{
//    
//}
//
//
//
//-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
//    
//}


-(void)viewWillAppear:(BOOL)animated{
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    //return cityArray.count;
    //NSLog(@"menuarr.count %lu",(unsigned long)menuarr.count);
    return menuarr.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *item = [menuarr objectAtIndex:section];
    //NSLog(@"item.count %lu",(unsigned long)item.count);
    return item.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    static NSString *ID = @"menuCell";
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
//    if (cell == nil) {
//        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
//    }
//    NSArray *array = [menuarr objectAtIndex:indexPath.section];
//    //NSLog(@"indexPath.row %ld",(long)indexPath.row);
//    NSDictionary *dic = [array objectAtIndex:indexPath.row];
//    //NSLog(@"cell dic %@",dic);
//
//    NSString *cityName = [dic valueForKey:@"title"];
//    cell.textLabel.text = cityName;
//    return cell;
    
    static NSString *strCell = @"indexTBVCell";
    IndexCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell];
    if (!cell) {
        cell = [[IndexCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCell];
    }
    //[cell setModel:self.datasource[indexPath.row]];
    NSArray *array = [menuarr objectAtIndex:indexPath.section];
    //    //NSLog(@"indexPath.row %ld",(long)indexPath.row);
    [cell setModel:[array objectAtIndex:indexPath.row]];
    
    return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { //头部高度
    return 60;
}
// 分组
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    NSArray *hadertitlearr = @[@"皇牌服務",@"全方位健康管理",@"promotion",@"關於Young+",@"聯絡Young+"];
    NSString *str = [hadertitlearr objectAtIndex:section];
    return str;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0,0,UISCREEN_WIDTH,SECTION_HEADER_HEIGHT)];
//    v.tag = section;
//    // UILabel *l = [[UILabel alloc] initWithFrame:   ]
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleSection:)];
//    [v addGestureRecognizer:tap];
    [v setBackgroundColor:[UIColor whiteColor]];
  
    if (UISCREEN_WIDTH <= 320) {
        CGRect tbheadviewRect = CGRectMake(10, 10,(UISCREEN_WIDTH - 10*2 -10)/2, 30); //单独设置CGRect
        imgVC = [[UIView alloc] initWithFrame:tbheadviewRect];
    }else{
        CGRect tbheadviewRect = CGRectMake((10*2 + 10)/2+10, 10,(UISCREEN_WIDTH- 10*2 -10)/2, 30);
        imgVC = [[UIView alloc] initWithFrame:tbheadviewRect];
    }
    //NSLog(@"iphone width : %f",UISCREEN_WIDTH);

    
    UIImageView *tbheaderimgV = [[UIImageView alloc]initWithFrame:CGRectMake( ((UISCREEN_WIDTH- 10*2 -10)/2 / 2 - 135/2), 0, 135, 30)];
    tbheaderimgV.image = [UIImage imageNamed:@"young_logo_180x40.png"];
    //tbheaderimgV.backgroundColor = [UIColor grayColor];// 背景色
    [imgVC addSubview:tbheaderimgV];
    //imgVC.backgroundColor = [UIColor grayColor];// 背景色
    [v addSubview:imgVC];
    
    NSArray *hadertitlearr = @[@"皇牌服務",@"全方位健康管理",@"promotion",@"關於Young+",@"聯絡Young+"];
    NSString *str = [hadertitlearr objectAtIndex:section]; //indexArray
    //NSLog(@"header title %@",str);
    
    UILabel *label =  [[UILabel alloc]initWithFrame:CGRectMake( (UISCREEN_WIDTH - 10*2 -10)/2 + 10, 10,(UISCREEN_WIDTH- 10*2 -10)/2, 30)];
    label.textAlignment = NSTextAlignmentCenter; //UITextAlignmentCenter 字體居中
    label.textColor = MENUBROWN;
    label.font = [UIFont systemFontOfSize:20.0];
    //label.backgroundColor = [UIColor redColor];// 背景色
    label.text = str;
    [v addSubview:label];
    
    return v;
}

// cell 指定的高度为300
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   // return 250;
    //NSLog(@"UISCREEN_WIDTH ,%f",((UISCREEN_WIDTH - 300)/2));
    return 370 ;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //NSString *itemDataSource = [menuarr objectAtIndex:indexPath.row];
    NSArray *array = [menuarr objectAtIndex:indexPath.section];
    NSDictionary *dicrow = [array objectAtIndex:indexPath.row];
    //NSLog(@"dicrow  %@",dicrow);
    
    //NSString *itemDataSource = [dicrow valueForKey:@"id"];title
    //NSString *itemDataSource = [dicrow valueForKey:@"title"];
    NSString *itemDataSource = [[NSString alloc] init];
    //NSNumber *B = [NSNumber numberWithInt:123456];
    NSNumber *B = [dicrow valueForKey:@"detail"];
    itemDataSource = [NSString stringWithFormat:@"%@",B];
    //NSLog(@"itemDataSource  %@",itemDataSource);
    
 
    
    itemVc = [[ItemViewController alloc]init];
    itemVc.itemDatasource = itemDataSource;
    [self.navigationController pushViewController:itemVc animated:true];
    //[self.navigationController pushViewController:vc_CitySelect animated:true];
}

-(void)setMenuData{
    //读取数组值
    NSMutableArray *MACArray = [[DataPersist readValueNSMutableArray:@"homeindex"] mutableCopy];
    //NSLog(@"MACArray %@ ",MACArray);
    NSMutableArray *dataarr = [MACArray valueForKey:@"data"];
    //NSLog(@"dataarr is %@",dataarr);
    
    //banner
    homebannerarr = [dataarr valueForKey:@"homeBanner"];
    //NSLog(@"homeBannerarr is %@",homebannerarr);
    //NSLog(@"imgbanner url %@",homebannerarr[1]);
    
    //字典   包含数组
    NSMutableArray *aceServicesarr = [dataarr valueForKey:@"aceServices"];
    NSArray *arra = [self setnewarr:aceServicesarr cate:@"aceServices"];
    //NSLog(@"arra %@",arra);
    
    NSMutableArray *healthManagementarr = [dataarr valueForKey:@"healthManagement"];
    NSArray *arrb = [self setnewarr:healthManagementarr cate:@"healthManagement"];
    
    
    NSMutableArray *menuarr2 = [[NSMutableArray alloc]init]; //菜单数组新建
    [menuarr2 addObject:arra];
    [menuarr2 addObject:arrb];
    //NSLog(@"menuarr.count %lu",(unsigned long)menuarr2.count);
    
    menuarr = [menuarr2 mutableCopy];
    //NSLog(@"menuarr.count %lu",(unsigned long)menuarr.count);
    //NSLog(@"menuarr %@",menuarr2);
}

-(NSMutableArray*)setnewarr:(NSMutableArray *)Mutbarr cate:(NSString*)cate{
    
    NSMutableArray * outputarr = [NSMutableArray array];
    
    for (NSMutableDictionary *dicset in Mutbarr) {  //循环。z将数组中值 循环到新数组
        
        //NSString *detail = [dicset valueForKey:@"detail"];
        //NSLog(@"detail %@",detail);
        
        NSMutableDictionary * mFirstDic = [[NSMutableDictionary alloc] init];
        NSArray *array1 = [dicset allKeys];
        
        [mFirstDic setValue:cate forKey:@"cate"];  //设置该分类名称
        
        
        for (int i = 0; i < array1.count; i++) {
            [mFirstDic setValue:[dicset valueForKey:@"detail"] forKey:@"detail"];
            [mFirstDic setValue:[dicset valueForKey:@"id"] forKey:@"id"];
            [mFirstDic setValue:[dicset valueForKey:@"img"] forKey:@"img"];
            [mFirstDic setValue:[dicset valueForKey:@"title"] forKey:@"title"];
        }
        //NSLog(@"mFirstDic %@",mFirstDic);
        
        [outputarr addObject:mFirstDic];
    }
    
    return outputarr;
}


-(void)loadingView{
    
    CGRect frame = CGRectMake(0, 0, 100, 100);
    UIView *activityBg = [[UIView alloc]initWithFrame:frame];
    activityBg.center = self.view.center;
    activityBg.backgroundColor = [UIColor grayColor];
    activityBg.alpha = 0.7;
    activityBg.layer.cornerRadius = 5.0;
    //[self.view addSubview:activityBg];
    [self.view addSubview:activityBg];
    
    UIActivityIndicatorView *loadActivity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    loadActivity.frame = CGRectMake(30, 30, 40, 40);
    [loadActivity sizeToFit];
    loadActivity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    [activityBg addSubview:loadActivity];
    [loadActivity startAnimating];
    
}
    -(void)getnetworkData{
         /*获取Home banner 数据*/
        //请勿删除
        network *gethomebanner = [[network alloc]init];
        [gethomebanner AppGetHomeBanner];
    }

-(void)setIndexView{
    [self setindexdata]; //设置首页数据
    [self setMenuData];
    [self settableView];
}
-(void)setindexdata{
    //读取数组值
    NSMutableArray *MACArray = [[DataPersist readValueNSMutableArray:@"homeindex"] mutableCopy];
    //NSLog(@"MACArray %@ ",MACArray);
    NSMutableArray *dataarr = [MACArray valueForKey:@"data"];
    //NSLog(@"dataarr is %@",dataarr);
    
    //banner
    homebannerarr = [dataarr valueForKey:@"homeBanner"];
    //NSLog(@"homeBannerarr is %@",homebannerarr);
    //NSLog(@"imgbanner url %@",homebannerarr[1]);
    
    //字典   包含数组
    NSMutableArray *aceServicesarr = [dataarr valueForKey:@"aceServices"];
    NSArray *arra = [self setnewarr:aceServicesarr cate:@"aceServices"];
    //NSLog(@"arra %@",arra);
    
    NSMutableArray *healthManagementarr = [dataarr valueForKey:@"healthManagement"];
    NSArray *arrb = [self setnewarr:healthManagementarr cate:@"healthManagement"];
    
    
    NSMutableArray *menuarr2 = [[NSMutableArray alloc]init]; //菜单数组新建
    [menuarr2 addObject:arra];
    [menuarr2 addObject:arrb];
    //NSLog(@"menuarr.count %lu",(unsigned long)menuarr2.count);
    
    menuarr = [menuarr2 mutableCopy];
    //NSLog(@"menuarr.count %lu",(unsigned long)menuarr.count);
    //NSLog(@"menuarr %@",menuarr2);
    
 
    //NSLog(@"第一次读取的值MACArray value is:%@",MACArray);
    
    //        NSMutableArray *dataarr = [MACArray valueForKey:@"data"];
    //
//    NSString *item3 = [homeBannerarr firstObject];
//    //NSLog(@"item3  %@",item3);
//    [DataPersist writeValuePre:item3 key:@"banner1"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

- (void)linshiBTNView {  //首页临时按钮
    BOOL avtBtn1 = false;
    
    if (avtBtn1) {
        _registerBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, UISCREEN_HEIGHT - 50, 100, 30)];    _registerBtn.backgroundColor = [UIColor lightGrayColor];
        [_registerBtn setTitle:@"本地通知" forState:UIControlStateNormal];
        [_registerBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_registerBtn addTarget:self action:@selector(localNotifAction) forControlEvents:UIControlEventTouchUpInside];
        _registerBtn.layer.borderWidth = 1.0;
        _registerBtn.layer.cornerRadius = 3.0;
        [self.view addSubview:_registerBtn];
    }
    
  
    
    
//    _aboutusOCBtn = [[UIButton alloc]initWithFrame:CGRectMake(140, UISCREEN_HEIGHT - 50, 100, 30)];
//    _aboutusOCBtn.backgroundColor = [UIColor lightGrayColor];
//    [_aboutusOCBtn setTitle:@"OCBtn" forState:UIControlStateNormal];
//    [_aboutusOCBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [_aboutusOCBtn addTarget:self action:@selector(aboutusOCAction) forControlEvents:UIControlEventTouchUpInside];
//    _aboutusOCBtn.layer.borderWidth = 1.0;
//    _aboutusOCBtn.layer.cornerRadius = 3.0;
//    [self.view addSubview:_aboutusOCBtn];
    
    
    UIButton *testvcBtn = [[UIButton alloc]initWithFrame:CGRectMake(UISCREEN_WIDTH - 120, UISCREEN_HEIGHT - 50, 100, 30)];
    testvcBtn.backgroundColor = [UIColor greenColor];
    [testvcBtn setTitle:@"testvcBtn" forState:UIControlStateNormal];
    [testvcBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [testvcBtn addTarget:self action:@selector(testvcBtnAction) forControlEvents:UIControlEventTouchUpInside];
    testvcBtn.layer.borderWidth = 1.0;
    testvcBtn.layer.cornerRadius = 3.0;
    [self.view addSubview:testvcBtn];
}

-(void)registerAction:(id)sender
{
    ViewController2TVC *registerVC = [[ViewController2TVC alloc]init];
    [self.navigationController pushViewController:registerVC animated:YES];
    
}

-(void)qrcodeAction{
    NSLog(@"click home");
//    if (vc_login == nil) {
//        vc_login = [[LoginViewController alloc]init];
//    }
//    [self presentViewController:vc_login animated:true completion:nil];
    [self.navigationController popToRootViewControllerAnimated:YES]; //IOS 返回根视图
}

-(void)menuBtnAction{
     NSLog(@"click menu");
    if (vc_menuVC == nil) {
        vc_menuVC = [[menuViewController alloc]init]; //MenutbVC
    }
    //    [self presentViewController:vc_citySelect animated:true completion:nil];
    [self.navigationController pushViewController:vc_menuVC animated:true];
}

-(void)aboutusOCAction{
    NSLog(@"click vc_menuVC");
    if (promotVC == nil) {
        promotVC = [[promotionTVC alloc]init];
    }
    //[self presentViewController:vc_menuVC animated:true completion:nil];
    
    //[self.navigationController pushViewController:promotVC animated:true];
    
    promotVC = [[promotionTVC alloc]init];
    promotVC.itemDatasource = @"83";
    [self.navigationController pushViewController:promotVC animated:true];
}

-(void)localNotifAction{
    NSLog(@"click NotificationVC");
    if (vc_Notification == nil) {
        vc_Notification = [[NotificationVC alloc]init];
    }
    //[self presentViewController:vc_menuVC animated:true completion:nil];
    [self.navigationController pushViewController:vc_Notification animated:true];
//    if (vc_WKWeb == nil) {
//                vc_WKWeb = [[WKWebViewController alloc]init];
//            }
//        //WKWebViewController *wkWebVC = [[WKWebViewController alloc] init];
//    [self.navigationController pushViewController:vc_WKWeb animated:YES];   //同一个navigationController。推出子视图
//    //[self presentViewController:vc_WKWeb animated:true completion:nil];  //推一个子视图覆盖
}

-(void)aboutusSwiftAction{
   NSLog(@"click aboutusSwiftAction");
    //    if (vc_aboutUsOC == nil) {
    //        vc_aboutUsOC = [[aboutUsVC alloc]init];
    //    }
    //    [self presentViewController:vc_aboutUsOC animated:true completion:nil];
    
    // Swift文件
    //    ChildViewController *vc = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
    //    [self.navigationController pushViewController:vc animated:YES];
    //    ForthViewController *forthViewVC = [[ForthViewController alloc]init];
    //    [self presentViewController:forthViewVC animated:YES completion:nil];
    aboutUsSwiftVC *vc_aboutUSswift = [[aboutUsSwiftVC alloc]init];
    //[self presentViewController:vc_aboutUSswift animated:YES completion:nil];  //推一个子视图覆盖
     [self.navigationController pushViewController:vc_aboutUSswift animated:YES];   //同一个navigationController。推出子视图
}

-(void)testvcBtnAction{
    
    NSLog(@"click testVCBtn");
    if (testvc == nil) {
        testvc = [[testVC alloc]init];
    }
    //[self presentViewController:testvc animated:YES completion:nil];  //推一个子视图覆盖
    [self.navigationController pushViewController:testvc animated:YES];   //同一个navigationController。推出子视图
}

#pragma 立刻预约页面
-(void)bookingview{
    // 5 弹出框 100=40 + 60
    loginView2 = [[UIView alloc]initWithFrame:CGRectMake(UISCREEN_WIDTH - 40, (UISCREEN_HEIGHT-140)/2, UISCREEN_WIDTH, 140)];
    loginView2.backgroundColor = [UIColor clearColor];
    UIButton *bt_login2 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 140)];
    ////  圆角效果
    loginView2.layer.cornerRadius = 2;
    //[bt_login2 setTitle:@"--换种方式--" forState:UIControlStateNormal];
    
    //[bt_login2 setTitleColor:[UIColor colorWithRed:50/255.0 green:189/255.0 blue:170/255.0 alpha:1.0] forState:UIControlStateNormal];
    [bt_login2 addTarget:self action:@selector(applyAction1) forControlEvents:UIControlEventTouchUpInside];
    [bt_login2 setBackgroundImage:[UIImage imageNamed:@"book_40x140.png"] forState:UIControlStateNormal]; //customer_service_50x150
    [loginView2 addSubview:bt_login2];
    
//    UIImageView *applyImg = [[UIImageView alloc]initWithFrame:CGRectMake((UISCREEN_WIDTH-40-40-20)/2, 50, 40, 40)];
//    applyImg.image = [UIImage imageNamed:@"customer_service_50x150.png"];
//    [bt_login2 addTarget:self action:@selector(applyAction2) forControlEvents:UIControlEventTouchUpInside];
//    [loginView2 addSubview:applyImg];
    
    [self.view addSubview:loginView2];
    
//    UIImageView *loginQQ = [[UIImageView alloc]initWithFrame:CGRectMake((UISCREEN_WIDTH-40-40-20)/2, 50, 40, 40)];
//    loginQQ.image = [UIImage imageNamed:@"2.png"];
//    [loginView2 addSubview:loginQQ];
//
//    UIImageView *loginchat = [[UIImageView alloc]initWithFrame:CGRectMake((UISCREEN_WIDTH-40-40-20)/2+60, 50, 40, 40)];
//    loginchat.image = [UIImage imageNamed:@"3.png"];
//    [loginView2 addSubview:loginchat];
}



-(void)applyAction1{
    if (contvc2 == nil) {
        contvc2 = [[contactTVC2 alloc]init];
    }
    [contvc2 setMenutype:1];  //设置联系我们类型，单一状态
    //[self presentViewController:vc_aboutUSswift animated:YES completion:nil];  //推一个子视图覆盖
    [self.navigationController pushViewController:contvc2 animated:YES];   //同一个navigationController。推出子视图
}

-(void)applyAction2{
    // 动画 1 动画开始 2 设置动画属性 3 动画执行
    // 1 动画开始
    [UIView beginAnimations:nil context:nil];
    // 2 周期
    [UIView setAnimationDuration:0.5];
    if (!login2hidden) {
        loginView2.frame = CGRectMake(UISCREEN_WIDTH - 50, (UISCREEN_HEIGHT-150)/2, UISCREEN_WIDTH, 150);
    }else{
        loginView2.frame = CGRectMake(0, (UISCREEN_HEIGHT-150)/2, UISCREEN_WIDTH, 150);
    }
    login2hidden = !login2hidden;
    // 3 动画执行
    [UIView commitAnimations];
}

///循环滚动
//1、时刻监听 ：回调
//2、合适的位置：跳转逻辑
//3 、5个页面
//-(void)scrollview3{
//    UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 50, 414, 200)];
//    scrollview.contentSize = CGSizeMake(414*5, 200);
//
//    scrollview.delegate  = self;
//    scrollview.pagingEnabled = true;
//    UILabel *label =  [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
//    label.backgroundColor = [UIColor redColor];
//    label.text = @"2";
//    [scrollview addSubview:label];
//    scrollview.contentOffset = CGPointMake(414, 0);//初始化偏移量
//
//    for (int i = 0 ; i<4; i++){
//        float labelX = (i+1)*414;
//        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(labelX, 0, 100, 100)];
//        label.backgroundColor = [UIColor redColor];
//        label.text = [NSString stringWithFormat:@"%d",i%3]; //0 1 2 0
//        [scrollview addSubview:label];
//    }
//    [self.view addSubview:scrollview];
//}
/*
-(void)scrollview2{
//    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1.jpg"]];
//    [self.view addSubview:imageView];
//
//    //NSStringFromCGSize(<#CGSize size#>) 打印 CGSize
//    NSLog(@"image:%@",NSStringFromCGSize(imageView.frame.size));
//    NSLog(@"SCREEN:%@",NSStringFromCGSize([UIScreen mainScreen].bounds.size));
    
    //frame contentsize   相等  不能滚动
    UIScrollView *scrollview2 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 100, 414, 200)];
    scrollview2.contentSize = CGSizeMake(1440, 900);
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(0,100, 1440, 900)];
    imageview.image = [UIImage imageNamed:@"1.jpg"];
    scrollview2.backgroundColor = [UIColor grayColor];
    [scrollview2 addSubview:imageview];
    [self.view addSubview:scrollview2];
}
*/
/*
-(void)scrollview1{
    UIScrollView *scrollview1 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 50, 414, 200)];
    scrollview1.contentSize = CGSizeMake(414*5, 200);
    
    scrollview1.contentOffset = CGPointMake(414, 0);//初始化偏移量
    scrollview1.backgroundColor = [UIColor grayColor];
    scrollview1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scrollview1.bounces = true; //是否有反弹效果
    scrollview1.pagingEnabled = true; //分页
    scrollview1.scrollEnabled = true; //是否翻页
    scrollview1.delegate = self;
    [self.view addSubview:scrollview1];
    
    
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(414, 0, 414, 50)];
    lab.text = @"hello";
    lab.textColor = [UIColor redColor];
    lab.backgroundColor = [UIColor whiteColor];
    lab.font = [UIFont systemFontOfSize:12.0];
    [scrollview1 addSubview:lab];
}
 */


-(void)imagePlay{  //自动播放
    pageControl.currentPage = imageIndex;
    sv_image.contentOffset  = CGPointMake(imageIndex*UISCREEN_WIDTH, 0);
    imageIndex++;
    if (imageIndex>=homebannerarr.count) {
        imageIndex = 0;
    }
    
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{  //拉动滚动视图
    float x = scrollView.contentOffset.x;
    imageIndex = x/UISCREEN_WIDTH;
}
// 销毁
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"getIndexNOTIF" object:nil];
}
@end
